﻿using Sustainalytics.ClientDW.DataAccessLayer;
using Sustainalytics.ClientDW.Entities;
using System;

namespace Sustainalytics.GCCS
{
    public class GCPrincipleConclusionManager : IGCPrincipleConclusionManager
    {
        private readonly IClientDWGlobalCompactRepository _gccRepo;

        public GCPrincipleConclusionManager(IClientDWGlobalCompactRepository gccRepo)
        {
            this._gccRepo = gccRepo;
        }

        public GCPrincipleConclusion GetByPrincipleSummary(Guid principleSummaryId)
        {
            try
            {
                GCCEventSource.Log.GCPrincipleConclusion_GetByPrincipleSummary(principleSummaryId);

                GCPrincipleConclusion data = this._gccRepo.GetGCPrincipleConclusionByPrincipleSummary(principleSummaryId);

                if (data == null)
                {
                    throw new GCPrincipleConclusionNotFoundException();
                }

                GCCEventSource.Log.GCPrincipleConclusion_GetByPrincipleSummary_Success(principleSummaryId);

                return data;
            }
            catch (Exception ex)
            {
                GCCEventSource.Log.GCPrincipleConclusion_GetByPrincipleSummary_Error(principleSummaryId, ex);
                throw;
            }
        }
    }
}
